# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Martell Malone <martellmalone@gmail.com>

pkgname=cmake
pkgver=3.2.3
pkgrel=1
pkgdesc="A cross-platform open-source make system"
arch=('i686' 'x86_64')
url="http://www.cmake.org/"
license=("MIT")
makedepends=("gcc" "pkg-config"
             #jsoncpp
             libcurl-devel
             libexpat-devel
             libarchive-devel
             ncurses-devel
             zlib-devel)
depends=("gcc-libs"
         "libcurl"
         "libexpat"
         "libarchive"
         "ncurses"
         "pkg-config"
         "zlib")
options=('staticlibs' 'strip')
source=("http://www.cmake.org/files/v3.2/${pkgname}-${pkgver}.tar.gz"
        "cmake-3.2.3-msys.patch"
        "disable-curses-for-msys.patch"
        "disable-response-files-for-msys.patch"
        3.1.0-case-sensitivity.patch
        3.1.0-cpuinfo.patch
        3.1.0-cygwin-paths.patch)
md5sums=('d51c92bf66b1e9d4fe2b7aaedd51377c'
         '13b8b8202f5af9169222ad392f1ad2ec'
         'acfb392eaebbb42f96884d6236a735ed'
         'fa5a731147dd979c8ac21b1ce0092d2b'
         'd25a959f840a03943e8af2dd8205cab4'
         '030e9e7dfd06f709c1e2511c38dfc555'
         '0765cb82393049f863c94335473f1f40')

prepare() {
  cd ${pkgname}-${pkgver}

  patch -p1 -i ${srcdir}/cmake-3.2.3-msys.patch
  patch -p1 -i ${srcdir}/disable-curses-for-msys.patch
  patch -p1 -i ${srcdir}/disable-response-files-for-msys.patch
  patch -p1 -i ${srcdir}/3.1.0-case-sensitivity.patch
  patch -p1 -i ${srcdir}/3.1.0-cpuinfo.patch
  patch -p1 -i ${srcdir}/3.1.0-cygwin-paths.patch

}

build() {
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

  MSYSTEM=MSYS "${srcdir}"/${pkgname}-${pkgver}/configure \
    --prefix=/usr \
    --system-libs \
    --no-system-expat \
    --no-system-jsoncpp \
    --no-qt-gui \
    --parallel=3 \
    --mandir=share \
    --docdir=share/doc/cmake

  plain "Start building..."
  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR=$pkgdir install
  
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/Copyright.txt \
    "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}
